﻿@*
    文件
*@

@using System.Diagnostics;
@using NewLife.Common;
@using NewLife.Cube.Admin;
@using NewLife;
@{
    var fs = Model as List<FileItem>;
    var r = ViewBag.Current as String;
    var clips = ViewBag.Clip as ICollection<FileItem>;
}

<div class="card">
    <div class="card-body py-5">


        <form action="~/Admin/File" id="tool" method="post">
            <div class="row align-items-start">
                <div class="col">
                    
                    <div class="input-group mb-5 input-group-sm">
                        <span class="input-group-text" id="basic-addon3">
                            <i class="las la-wallet fs-1"></i>
                        </span>
                        <input type="search" class="form-control" id="r" name="r" value="@r" placeholder="当前路径">
                        <button type="submit" class="input-group-text bg-light-warning hoverable text-info ms-2">
                            <i class="fas fa-folder-open fs-4 me-2 text-info"></i>
                            <span class="" >打 开</span>
                        </button>
                    </div>

                    <div class="input-group mb-5 input-group-sm">
                        <input type="file" class="form-control" id="file" name="file" placeholder="上传文件">
                        <button type="submit" class="input-group-text bg-light-primary hoverable text-info ms-2" onclick="$('#tool').attr('action', '/Admin/File/Upload');$('#tool').attr('enctype', 'multipart/form-data'); return true;">
                            <i class="fas fa-upload fs-4 me-2 text-info"></i>
                            <span class="">上 传</span>
                        </button>
                    </div>
                </div>
                <div class="col">
                    @if (clips.Count > 0)
                    {
                        <div class="text-end mb-4">
                            <a href="/Admin/File/Paste?r=@r" class="btn btn-sm btn-outline btn-outline-dashed btn-outline-primary btn-active-light-primary">粘贴</a>
                            <a href="/Admin/File/Move?r=@r" class="btn btn-sm btn-outline btn-outline-dashed btn-outline-success btn-active-light-success">移动</a>
                            <a href="/Admin/File/ClearClipboard?r=@r" class="btn btn-sm btn-outline btn-outline-dashed btn-outline-info btn-active-light-info">清空</a>

                        </div>
                        <div class="text-end">
                            <span class="input-group-addon">
                                <i class="fas fa-hdd pe-3" title="剪切板共有 @clips.Count 项">&nbsp;&nbsp;  @clips.Count</i> 
                            </span>
                        </div>


                    }
                </div>

            </div>



        </form>
    </div>
</div>

<table class="table table-bordered table-hover table-striped table-condensed mb-0">
    <thead class="bg-white fw-bold fs-6 border border-bottom-3 border-gray-200">
        <tr>
            <th class="text-center"><a href="~/Admin/File?r=@r&sort=name">名称</a></th>
            <th class="text-center"><a href="~/Admin/File?r=@r&sort=size">大小</a></th>
            <th class="text-center"><a href="~/Admin/File?r=@r&sort=lastwrite">修改时间</a></th>
            <th class="text-center">复制</th>
            <th class="text-center">压缩</th>
            <th class="text-center">删除</th>
        </tr>
    </thead>
    <tbody class="border border-gray-300">
        @foreach (var item in fs)
        {
            <tr>
                @if (item.Directory)
                {
                    <td>&nbsp;&nbsp;<a href="~/Admin/File?r=@item.FullName" title="进入目录">@item.Name</a></td>
                }
                else
                {
                    <td>&nbsp;&nbsp;<a href="~/Admin/File/Download?r=@item.FullName" title="下载文件">@item.Name</a></td>
                }
                <td class="text-right">@item.Size</td>
                <td class="text-center">@item.LastWrite.ToFullString("")</td>
                <td class="text-center">
                    @if (!clips.Any(e => e.FullName == item.FullName))
                    {
                        <a href="~/Admin/File/Copy?r=@r&f=@item.FullName" title="复制到剪切板，然后去目标目录粘贴">复制</a>
                    }
                    else
                    {
                        <a href="~/Admin/File/CancelCopy?r=@r&f=@item.FullName" title="从剪切板移除">取消复制</a>
                    }
                </td>
                @if (item.Name.EndsWithIgnoreCase(".zip"))
                {
                    <td class="text-center"><a href="~/Admin/File/Decompress?r=@item.FullName" title="解压缩到当前目录">解压缩</a></td>
                }
                else
                {
                    <td class="text-center"><a href="~/Admin/File/Compress?r=@item.FullName" title="压缩到当前目录，加上时间后缀">压缩</a></td>
                }
                <td class="text-center"><a href="~/Admin/File/Delete?r=@item.FullName" onclick="return confirm('确认删除？');">删除</a></td>
            </tr>
        }
    </tbody>
</table>

